package com.one.shopping.ui.activity;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.one.shopping.R;
import com.one.shopping.entity.Users;
import com.one.shopping.ui.baseActivity.BaseActivity;

/**
 * @author 柯尊诚
 * @version 1.0
 * @date 创建时间：2016/1/10 16:13
 */
public class UserDetailActivity extends BaseActivity {

    private TextView userIdValues;
    private TextView userNameValues;
    private TextView userPasswdValues;
    private TextView userTypeValues;
    private Button userUpdateBtn;
    private Users users;

    @Override
    protected int getContentViewId() {
        return R.layout.list_user_detail;
    }

    @Override
    protected void initView() {
        super.initView();
        setTitle("收银员详情");
        isVisibleAdd(true);

        userIdValues = findView(R.id.user_detail_id_values_tv);
        userNameValues = findView(R.id.user_detail_name_values_tv);
        userPasswdValues = findView(R.id.user_detail_passwd_values_tv);
        userTypeValues = findView(R.id.user_detail_type_values_tv);
        userUpdateBtn = findView(R.id.user_update_btn);
    }

    @Override
    protected void initData() {
        super.initData();
        Intent intent = getIntent();
        users = (Users)intent.getSerializableExtra("users");

        userIdValues.setText(""+users.getId());
        userNameValues.setText(users.getName());
        userPasswdValues.setText(users.getPasswd());
        userTypeValues.setText("收银员");
    }

    @Override
    protected void initListener() {
        super.initListener();

        addBtn.setOnClickListener(onClickAddBtnListener);

        userUpdateBtn.setOnClickListener(onClickUpdateBtnListener);
    }


    /**
     * 点击添加按钮
     */
    private View.OnClickListener onClickAddBtnListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
            Intent intent = new Intent(UserDetailActivity.this, AddUserActivity.class);
            startActivity(intent);
        }
    };

    /**
     * 点击更新按钮
     */
    private View.OnClickListener onClickUpdateBtnListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();
            Intent intent = new Intent(UserDetailActivity.this, AddUserActivity.class);
            Bundle bundle = new Bundle();
            bundle.putSerializable("users", users);
            intent.putExtras(bundle);
            startActivity(intent);
        }
    };


}
